﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using AutoR.Models;
using AutoR.Services;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services;

namespace AutoR.ViewModels.Setting
{
	// Token: 0x02000096 RID: 150
	public class ShipConfigViewModel : BindableBase, INavigationAware, INavigatedAware, INavigatingAware
	{
		// Token: 0x170000A6 RID: 166
		// (get) Token: 0x060002AC RID: 684 RVA: 0x00047062 File Offset: 0x00045262
		// (set) Token: 0x060002AD RID: 685 RVA: 0x0004706C File Offset: 0x0004526C
		public UserShip Ship
		{
			[CompilerGenerated]
			get
			{
				return this.<Ship>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Ship>k__BackingField, value))
				{
					return;
				}
				this.<Ship>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Ship);
			}
		}

		// Token: 0x170000A7 RID: 167
		// (get) Token: 0x060002AE RID: 686 RVA: 0x0004709C File Offset: 0x0004529C
		private INavigationService NavigationService { get; }

		// Token: 0x170000A8 RID: 168
		// (get) Token: 0x060002AF RID: 687 RVA: 0x000470A4 File Offset: 0x000452A4
		private IPageDialogService PageDialogService { get; }

		// Token: 0x170000A9 RID: 169
		// (get) Token: 0x060002B0 RID: 688 RVA: 0x000408F6 File Offset: 0x0003EAF6
		public GameData Game
		{
			get
			{
				return Runtime.Game;
			}
		}

		// Token: 0x170000AA RID: 170
		// (get) Token: 0x060002B1 RID: 689 RVA: 0x000470AC File Offset: 0x000452AC
		// (set) Token: 0x060002B2 RID: 690 RVA: 0x000470B4 File Offset: 0x000452B4
		public ObservableCollection<UserShip> List
		{
			[CompilerGenerated]
			get
			{
				return this.<List>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<List>k__BackingField, value))
				{
					return;
				}
				this.<List>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.List);
			}
		}

		// Token: 0x170000AB RID: 171
		// (get) Token: 0x060002B3 RID: 691 RVA: 0x000470E4 File Offset: 0x000452E4
		// (set) Token: 0x060002B4 RID: 692 RVA: 0x000470EC File Offset: 0x000452EC
		public UserShip SelectShip
		{
			[CompilerGenerated]
			get
			{
				return this.<SelectShip>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<SelectShip>k__BackingField, value))
				{
					return;
				}
				this.<SelectShip>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.SelectShip);
			}
		}

		// Token: 0x170000AC RID: 172
		// (get) Token: 0x060002B5 RID: 693 RVA: 0x0004711C File Offset: 0x0004531C
		// (set) Token: 0x060002B6 RID: 694 RVA: 0x00047124 File Offset: 0x00045324
		public int ShipType
		{
			[CompilerGenerated]
			get
			{
				return this.<ShipType>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<ShipType>k__BackingField == value)
				{
					return;
				}
				this.<ShipType>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.ShipType);
			}
		}

		// Token: 0x170000AD RID: 173
		// (get) Token: 0x060002B7 RID: 695 RVA: 0x00047151 File Offset: 0x00045351
		// (set) Token: 0x060002B8 RID: 696 RVA: 0x0004715C File Offset: 0x0004535C
		public List<UserEquipment> Equip
		{
			[CompilerGenerated]
			get
			{
				return this.<Equip>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equip>k__BackingField, value))
				{
					return;
				}
				this.<Equip>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equip);
			}
		}

		// Token: 0x170000AE RID: 174
		// (get) Token: 0x060002B9 RID: 697 RVA: 0x0004718C File Offset: 0x0004538C
		// (set) Token: 0x060002BA RID: 698 RVA: 0x00047194 File Offset: 0x00045394
		public UserEquipment SelectedItem
		{
			[CompilerGenerated]
			get
			{
				return this.<SelectedItem>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<SelectedItem>k__BackingField, value))
				{
					return;
				}
				this.<SelectedItem>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.SelectedItem);
			}
		}

		// Token: 0x170000AF RID: 175
		// (get) Token: 0x060002BB RID: 699 RVA: 0x000471C4 File Offset: 0x000453C4
		// (set) Token: 0x060002BC RID: 700 RVA: 0x000471CC File Offset: 0x000453CC
		public EquipmentConfig SelectEquip
		{
			[CompilerGenerated]
			get
			{
				return this.<SelectEquip>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<SelectEquip>k__BackingField, value))
				{
					return;
				}
				this.<SelectEquip>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.SelectEquip);
			}
		}

		// Token: 0x170000B0 RID: 176
		// (get) Token: 0x060002BD RID: 701 RVA: 0x000471FC File Offset: 0x000453FC
		// (set) Token: 0x060002BE RID: 702 RVA: 0x00047204 File Offset: 0x00045404
		public int SelectPos
		{
			[CompilerGenerated]
			get
			{
				return this.<SelectPos>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<SelectPos>k__BackingField == value)
				{
					return;
				}
				this.<SelectPos>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.SelectPos);
			}
		}

		// Token: 0x170000B1 RID: 177
		// (get) Token: 0x060002BF RID: 703 RVA: 0x00047231 File Offset: 0x00045431
		// (set) Token: 0x060002C0 RID: 704 RVA: 0x0004723C File Offset: 0x0004543C
		public EquipmentConfig Equipment1
		{
			[CompilerGenerated]
			get
			{
				return this.<Equipment1>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equipment1>k__BackingField, value))
				{
					return;
				}
				this.<Equipment1>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equipment1);
			}
		}

		// Token: 0x170000B2 RID: 178
		// (get) Token: 0x060002C1 RID: 705 RVA: 0x0004726C File Offset: 0x0004546C
		// (set) Token: 0x060002C2 RID: 706 RVA: 0x00047274 File Offset: 0x00045474
		public EquipmentConfig Equipment2
		{
			[CompilerGenerated]
			get
			{
				return this.<Equipment2>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equipment2>k__BackingField, value))
				{
					return;
				}
				this.<Equipment2>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equipment2);
			}
		}

		// Token: 0x170000B3 RID: 179
		// (get) Token: 0x060002C3 RID: 707 RVA: 0x000472A4 File Offset: 0x000454A4
		// (set) Token: 0x060002C4 RID: 708 RVA: 0x000472AC File Offset: 0x000454AC
		public EquipmentConfig Equipment3
		{
			[CompilerGenerated]
			get
			{
				return this.<Equipment3>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equipment3>k__BackingField, value))
				{
					return;
				}
				this.<Equipment3>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equipment3);
			}
		}

		// Token: 0x170000B4 RID: 180
		// (get) Token: 0x060002C5 RID: 709 RVA: 0x000472DC File Offset: 0x000454DC
		// (set) Token: 0x060002C6 RID: 710 RVA: 0x000472E4 File Offset: 0x000454E4
		public EquipmentConfig Equipment4
		{
			[CompilerGenerated]
			get
			{
				return this.<Equipment4>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equipment4>k__BackingField, value))
				{
					return;
				}
				this.<Equipment4>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equipment4);
			}
		}

		// Token: 0x170000B5 RID: 181
		// (get) Token: 0x060002C7 RID: 711 RVA: 0x00047314 File Offset: 0x00045514
		public DelegateCommand OKCommand { get; }

		// Token: 0x170000B6 RID: 182
		// (get) Token: 0x060002C8 RID: 712 RVA: 0x0004731C File Offset: 0x0004551C
		public DelegateCommand RemoveCommand { get; }

		// Token: 0x170000B7 RID: 183
		// (get) Token: 0x060002C9 RID: 713 RVA: 0x00047324 File Offset: 0x00045524
		public DelegateCommand<string> SelectEquipCommand { get; }

		// Token: 0x170000B8 RID: 184
		// (get) Token: 0x060002CA RID: 714 RVA: 0x0004732C File Offset: 0x0004552C
		public DelegateCommand EquipOKCommand { get; }

		// Token: 0x170000B9 RID: 185
		// (get) Token: 0x060002CB RID: 715 RVA: 0x00047334 File Offset: 0x00045534
		public DelegateCommand EquipRemoveCommand { get; }

		// Token: 0x060002CC RID: 716 RVA: 0x0004733C File Offset: 0x0004553C
		public ShipConfigViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
		{
			this.NavigationService = navigationService;
			this.PageDialogService = pageDialogService;
			this.GenList();
			this.OKCommand = new DelegateCommand(new Action(this.OnOKCommandExecuted));
			this.RemoveCommand = new DelegateCommand(new Action(this.OnRemoveCommandExecuted));
			this.EquipOKCommand = new DelegateCommand(new Action(this.OnEquipOKCommandExecuted));
			this.EquipRemoveCommand = new DelegateCommand(new Action(this.OnEquipRemoveCommandExecuted));
			this.SelectEquipCommand = new DelegateCommand<string>(delegate(string s)
			{
				if (this.Ship.Equipment.Count >= Convert.ToInt32(s) + 1)
				{
					this.SelectEquip = this.Ship.Equipment[Convert.ToInt32(s)];
					this.SelectPos = Convert.ToInt32(s);
				}
			});
		}

		// Token: 0x060002CD RID: 717 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatedFrom(INavigationParameters parameters)
		{
		}

		// Token: 0x060002CE RID: 718 RVA: 0x000473D8 File Offset: 0x000455D8
		public void OnNavigatedTo(INavigationParameters parameters)
		{
			if (parameters.ContainsKey("ship"))
			{
				this.Ship = (UserShip)parameters["ship"];
				this.Equip = (from i in this.Game.Equipments
				where i.num > 0 && i.ShipType.Contains(this.Ship.Type)
				orderby i.Type, i.Star
				select i).ToList<UserEquipment>();
			}
		}

		// Token: 0x060002CF RID: 719 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatingTo(INavigationParameters parameters)
		{
		}

		// Token: 0x060002D0 RID: 720 RVA: 0x0004747C File Offset: 0x0004567C
		public void GenList()
		{
			List<UserShip> list = this.Game.UserShip.ToList<UserShip>();
			if (this.ShipType != 0)
			{
				int[] id = new int[]
				{
					0,
					1,
					2,
					3,
					4,
					5,
					6,
					7,
					8,
					9,
					10,
					11,
					12,
					13,
					14,
					15,
					16,
					23,
					24
				};
				list = (from i in list
				where i.Type == (ShipType)id[this.ShipType]
				select i).ToList<UserShip>();
			}
			list = (from i in list
			orderby i.level descending, i.Type descending
			select i).ToList<UserShip>();
			this.List = new ObservableCollection<UserShip>(list);
		}

		// Token: 0x060002D1 RID: 721 RVA: 0x0004753C File Offset: 0x0004573C
		private async void OnRemoveCommandExecuted()
		{
			if (this.Ship != null)
			{
				this.Game.DelayTask.ChangeBoatQueue.Enqueue(string.Format("{0}|{1}|0|1", this.Ship.fleetId, this.Ship.id));
				await this.PageDialogService.DisplayAlertAsync("提示", "已将移除船请求加入队列", "确定");
			}
			await this.NavigationService.GoBackAsync();
		}

		// Token: 0x060002D2 RID: 722 RVA: 0x00047578 File Offset: 0x00045778
		private async void OnOKCommandExecuted()
		{
			if (this.Ship != null)
			{
				foreach (UserFleet userFleet in this.Game.Fleet)
				{
					if (userFleet.UserShip.Contains(this.Ship))
					{
						int num = userFleet.UserShip.IndexOf(this.Ship);
						this.Game.DelayTask.ChangeBoatQueue.Enqueue(string.Format("{0}|{1}|{2}|0", userFleet.id, this.SelectShip.id, num));
						await this.PageDialogService.DisplayAlertAsync("提示", "已将换船请求加入队列", "确定");
						break;
					}
				}
				IEnumerator<UserFleet> enumerator = null;
			}
			await this.NavigationService.GoBackAsync();
		}

		// Token: 0x060002D3 RID: 723 RVA: 0x000475B4 File Offset: 0x000457B4
		private async void OnEquipRemoveCommandExecuted()
		{
			if (this.SelectEquip != null && this.SelectEquip.cid != -1)
			{
				this.Game.DelayTask.ChangeEquipmentQueue.Enqueue(string.Format("{0}|{1}|0|1", this.Ship.id, this.SelectPos));
				await this.PageDialogService.DisplayAlertAsync("提示", "已将移除装备请求加入队列", "确定");
			}
		}

		// Token: 0x060002D4 RID: 724 RVA: 0x000475F0 File Offset: 0x000457F0
		private async void OnEquipOKCommandExecuted()
		{
			if (this.SelectEquip != null && this.SelectedItem != null)
			{
				this.Game.DelayTask.ChangeEquipmentQueue.Enqueue(string.Format("{0}|{1}|{2}|0", this.Ship.id, this.SelectedItem.equipmentCid, this.SelectPos));
				await this.PageDialogService.DisplayAlertAsync("提示", "已将换装备请求加入队列", "确定");
			}
		}
	}
}
